import 'package:dio/dio.dart';
import 'package:flutter_wan_android/core/http/network_module.dart';
import 'package:flutter_wan_android/data/article/article_entity.dart';
import 'package:flutter_wan_android/data/base_data_layer_api.dart';
import 'package:flutter_wan_android/data/page_entity.dart';
import 'package:flutter_wan_android/data/wan_android_resp.dart';

/// 文章数据网络API
class ArticleNetworkApi {
  late final Dio _dio;

  ArticleNetworkApi(NetworkModule module) {
    _dio = module.dio;
  }

  Future<PageEntity<ArticleEntity>> requestList(int page) async {
    return performNetworkRequest(
      () async => await _dio.get("/article/list/$page/json"),
      (body) => WanAndroidResp.fromJson(
        body,
        (data) => PageEntity<ArticleEntity>.fromJson(
          data as Map<String, dynamic>,
          (item) => ArticleEntity.fromJson(item),
        ),
      ),
    );
  }
}
